package com.wikidot.designpatterns.builder;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Complex product which can be constructed in several ways. Construction of the
 * product is in concrete builder. This class provides only representation. The
 * setter methods does not contain logic for processing the input, they are
 * simple property access methods.
 */
class Label {
	private String id;

	private String description;

	private List<String> tags = new ArrayList<String>();

	public void setDescription(String description) {
		this.description = description;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setTag(String tag) {
		this.tags.add(tag);
	}

	/**
	 * This method just prints the label. It prints only information that has
	 * been set, empty items are omitted.
	 */
	public void printLabel() {
		StringBuilder label = new StringBuilder();
		label.append("Product Label\n");
		label.append("ID: ").append(this.id).append("\n");
		if (this.description != null && this.description.length() != 0) {
			// Don't print description if there is none.
			label.append("Description: ").append(this.description).append("\n");
		}
		if (!this.tags.isEmpty()) {
			// Don't print tags if there are none.
			label.append("Tags: ");
			for (Iterator<String> it = tags.iterator(); it.hasNext();) {
				String tag = it.next();
				label.append(tag);
				if (it.hasNext()) {
					label.append(" ");
				}
			}
			label.append("\n");
		}
		System.out.println(label.toString());
	}
}
